import { createRouter, createWebHistory } from "vue-router";
// 加载进度条
import NProgress from "nprogress";
import "nprogress/nprogress.css";

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: "/",
      redirect: "/home",
      name: "layout",
      component: () => import("../views/Layout/index.vue"),
      children: [
        {
          path: "/home",
          name: "home",
          component: () => import("../views/Home/index.vue"),
          meta: { title: "首页" },
        },
        // {
        //   path: '/article',
        //   name: 'article',
        //   component: () => import('../views/Article/index.vue'),
        //   meta: { title: '健康百科' }
        // },
        // {
        //   path: '/notify',
        //   name: 'notify',
        //   component: () => import('../views/Notify/index.vue'),
        //   meta: { title: '消息通知' }
        // },
        {
          path: '/user',
          name: 'user',
          component: () => import('../views/User/index.vue'),
          meta: { title: '个人中心' }
        }
      ],
    },
    {
      path: "/login",
      name: "login",
      component: () => import("../views/Login/index.vue"),
      meta: { title: "登录页面" },
    },
  ],
});

router.beforeEach((from, to, next) => {
  NProgress.start();
  next()
});

router.afterEach((to) => {
  document.title = `${to.meta.title || ""}`;
  NProgress.done();
});

export default router;
